import os
from celery import Celery
import logging

# 配置日志
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# 打印当前工作目录
logger.info(f"Current working directory: {os.getcwd()}")

# Redis配置
REDIS_URL = 'redis://:123456@localhost:6379/0'
logger.info(f"Using Redis URL: {REDIS_URL}")

# 创建 Celery 实例
celery_app = Celery('tasks')
logger.info("Created Celery app instance")

# Celery 配置
celery_app.conf.update(
    broker_url=REDIS_URL,
    result_backend=REDIS_URL,
    task_serializer='json',
    accept_content=['json'],
    result_serializer='json',
    timezone='Asia/Shanghai',
    enable_utc=True,
    imports=['tasks'],
    worker_prefetch_multiplier=1,
    task_acks_late=True,
    worker_log_format='[%(asctime)s: %(levelname)s/%(processName)s] %(message)s',
    worker_task_log_format='[%(asctime)s: %(levelname)s/%(processName)s][%(task_name)s(%(task_id)s)] %(message)s'
)

logger.info("Celery configuration loaded successfully") 